﻿<%@ Page Title="" Language="C#" MasterPageFile="~/AdminCP/Layouts/Admin.Master" AutoEventWireup="true"
    CodeBehind="ProductMananger.aspx.cs" Inherits="MLM.AdminCP.Pages.ProductMananger"
    meta:resourcekey="PageResource1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Label ID="lbName" runat="server" Text="Product Management" meta:resourcekey="lbNameResource1"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <telerik:RadAjaxManagerProxy runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadProductGrid">
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
    <telerik:RadGrid ID="RadProductGrid" runat="server" AllowFilteringByColumn="True"
        DataSourceID="GroupProductEds" AllowPaging="True" AllowSorting="True" GridLines="None"
        ShowGroupPanel="True"  AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
        AllowAutomaticDeletes="True" ShowFooter="True" ShowStatusBar="True" Height="800px"
        meta:resourcekey="RadProductGridResource1">
        <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True">
            <Selecting AllowRowSelect="True" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="ProductBaseID" DataSourceID="GroupProductEds"
            ShowHeader="true" ShowHeadersWhenNoRecords="true" AllowAutomaticInserts="true"
            CommandItemDisplay="TopAndBottom" EditMode="PopUp">
            <CommandItemSettings ShowAddNewRecordButton="true" ShowRefreshButton="true"></CommandItemSettings>
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn DataField="ProductBaseID" DataType="System.Int64" HeaderText="ID"
                    ReadOnly="True" SortExpression="ProductBaseID" UniqueName="ProductBaseID" HeaderStyle-Width="50px"
                    ItemStyle-Width="50px" meta:resourcekey="GridBoundColumnResource1" FilterControlWidth="50"
                    AllowFiltering="false">
                    <HeaderStyle Width="50px"></HeaderStyle>
                    <ItemStyle Width="200px"></ItemStyle>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ProductNumber" DataType="System.String" HeaderText="P.Number"
                    ReadOnly="True" SortExpression="ProductNumber" UniqueName="ProductNumber" HeaderStyle-Width="120px"
                    ItemStyle-Width="200px" meta:resourcekey="GridBoundColumnResource133">
                    <HeaderStyle Width="120px"></HeaderStyle>
                    <ItemStyle Width="120px"></ItemStyle>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
                    UniqueName="Name" HeaderStyle-Width="120px" ItemStyle-Width="200px" meta:resourcekey="GridBoundColumnResource2">
                    <HeaderStyle Width="120px"></HeaderStyle>
                    <ItemStyle Width="200px"></ItemStyle>
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn UniqueName="ThumbImage" DataField="ThumbImage" HeaderText="ThumbImage"
                    meta:resourcekey="GridTemplateColumnResource1" AllowFiltering="false">
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" Width="50px" Height="50px" ImageUrl='<%# Eval("ThumbImage") %>'
                            meta:resourcekey="Image1Resource1" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="StockAvailable" HeaderText="Available" SortExpression="StockAvailable"
                    UniqueName="StockAvailable" HeaderStyle-Width="120px" DataType="System.Int64"
                    meta:resourcekey="GridBoundColumnResource3">
                    <HeaderStyle Width="120px"></HeaderStyle>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ProductCategory.Name" HeaderText="Category" SortExpression="ProductCategory.Name"
                    UniqueName="ProductCategoryID" HeaderStyle-Width="120px" meta:resourcekey="GridBoundColumnResource4">
                    <HeaderStyle Width="120px"></HeaderStyle>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Points" DataType="System.Int64" HeaderText="Point"
                    SortExpression="Points" UniqueName="Points" DataFormatString="{0} PV" meta:resourcekey="GridBoundColumnResource5">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Price" DataType="System.Double" HeaderText="Price"
                    SortExpression="Price" UniqueName="Price" meta:resourcekey="GridBoundColumnResource6">
                </telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                    HeaderText="Edit" meta:resourcekey="GridEditCommandColumnResource1">
                    <ItemStyle CssClass="MyImageButton"></ItemStyle>
                    <HeaderStyle Width="50px"></HeaderStyle>
                </telerik:GridEditCommandColumn>
                <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                    UniqueName="DeleteColumn" HeaderText="Delete" meta:resourcekey="GridButtonColumnResource1">
                    <HeaderStyle Width="50px"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
                </telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings EditFormType="Template" InsertCaption="Add new item" CaptionFormatString="Edit ProductID: {0}"
                CaptionDataField="ProductBaseID" PopUpSettings-Modal="true" FormTableStyle-Width="600px">
                <EditColumn UniqueName="EditCommandColumn1">
                </EditColumn>
                <FormTableStyle Width="600px"></FormTableStyle>
                <FormTemplate>
                    <table id="Table2" style="border-collapse: collapse; padding-left: 20px; width: 600px">
                        <tr class="EditFormHeader" style="height: 10px">
                            <td style="font-size: small; width: 100px" colspan="2">
                                <b>
                                    <asp:Label ID="Label1" runat="server" Text="Product Infomation" meta:resourcekey="Label1Resource1"></asp:Label>
                                </b>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Product Number
                            </td>
                            <td> <telerik:RadTextBox CssClass="radtextbox" ID="RadTextBox5" runat="server" Text='<%# Bind("ProductNumber") %>'
                                    >
                                </telerik:RadTextBox>
                            </td>
                            <td colspan="2">
                            </td>
                        </tr>
                        <tr style="height: 30px">
                            <td class="titlename">
                                <asp:Label ID="lbName" runat="server" Text="Name:" meta:resourcekey="lbNameResource2"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadTextBox CssClass="radtextbox" ID="RadTextBox1" runat="server" Text='<%# Bind("Name") %>'
                                    LabelCssClass="" meta:resourcekey="RadTextBox1Resource1">
                                </telerik:RadTextBox>
                                <asp:RequiredFieldValidator ID="TextBoxRequiredFieldValidator" runat="server" Display="Dynamic"
                                    ControlToValidate="RadTextBox1" ErrorMessage="The textbox can not be empty!"
                                    meta:resourcekey="TextBoxRequiredFieldValidatorResource1"></asp:RequiredFieldValidator>
                            </td>
                            <td class="titlename">
                                <asp:Label ID="lbProductCategory" runat="server" Text="Product Category:" meta:resourcekey="lbProductCategoryResource1"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadComboBox class="rancombox" runat="server" ID="RadComboBox1" DataTextField="Name"
                                    DataValueField="ProductCategoryID" DataSourceID="GroupProductCategoryEds" SelectedValue='<%# Bind("ProductCategoryID") %>'
                                    EnableLoadOnDemand="True" meta:resourcekey="RadComboBox1Resource1">
                                </telerik:RadComboBox>
                            </td>
                        </tr>
                        <tr style="height: 30px">
                            <td class="titlename">
                                <asp:Label ID="lbPrice" runat="server" Text="Price:" meta:resourcekey="lbPriceResource1"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadTextBox CssClass="radtextbox" ID="RadTextBox2" runat="server" Text='<%# Bind("Price") %>'
                                    LabelCssClass="" meta:resourcekey="RadTextBox2Resource1">
                                </telerik:RadTextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
                                    ControlToValidate="RadTextBox2" ErrorMessage="The textbox can not be empty!"
                                    meta:resourcekey="RequiredFieldValidator1Resource1"></asp:RequiredFieldValidator>
                            </td>
                            <td class="titlename">
                                <asp:Label ID="lbStockAvailable" runat="server" Text="Stock Available:" meta:resourcekey="lbStockAvailableResource1"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadTextBox CssClass="radtextbox" ID="RadTextBox3" runat="server" Text='<%# Bind("StockAvailable") %>'
                                    LabelCssClass="" meta:resourcekey="RadTextBox3Resource1">
                                </telerik:RadTextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic"
                                    ControlToValidate="RadTextBox2" ErrorMessage="The textbox can not be empty!"
                                    meta:resourcekey="RequiredFieldValidator2Resource1"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr style="height: 30px">
                            <td class="titlename">
                                <asp:Label ID="lbPoints" runat="server" Text="Points:" meta:resourcekey="lbPointsResource1"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadTextBox CssClass="radtextbox" ID="RadTextBox4" runat="server" Text='<%# Bind("Points") %>'
                                    LabelCssClass="" meta:resourcekey="RadTextBox4Resource1">
                                </telerik:RadTextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" Display="Dynamic"
                                    ControlToValidate="RadTextBox4" ErrorMessage="The textbox can not be empty!"
                                    meta:resourcekey="RequiredFieldValidator3Resource1"></asp:RequiredFieldValidator>
                            </td>
                            <td class="titlename">
                                <asp:Label ID="lbVATT" runat="server" Text="VAT Type:" meta:resourcekey="lbVATTResource1"></asp:Label>
                            </td>
                            <td>
                                <telerik:RadComboBox runat="server" SelectedValue='<%# Bind("VATType") %>' ID="VATCbb"
                                    meta:resourcekey="VATCbbResource1">
                                    <Items>
                                        <telerik:RadComboBoxItem runat="server" Value="1" Text="Normal" meta:resourcekey="RadComboBoxItemResource1"
                                            Owner="" Selected="True" />
                                        <telerik:RadComboBoxItem runat="server" Value="2" Text="Special" meta:resourcekey="RadComboBoxItemResource2"
                                            Owner="" />
                                    </Items>
                                </telerik:RadComboBox>
                            </td>
                        </tr>
                        <tr style="height: 30px">
                            <td class="titlename">
                                <asp:Label ID="lbThumbImage" runat="server" Text="ThumbImage:" meta:resourcekey="lbThumbImageResource1"></asp:Label>
                            </td>
                            <td>
                                <div>
                                    <script type="text/javascript">
                                        //This function is called from the Explorer.aspx page
                                        function OpenFileExplorerDialog() {
                                            var inputID = '<%# Container.FindControl("fileName").ClientID %>';
                                            debugger;
                                            var wnd = $find('<%# Container.FindControl("ExplorerWindow").ClientID %>');
                                            wnd.show();

                                            //NEW: Set the ID of the textbox in a global variable            
                                            currentInputID = inputID;
                                        }
                                        function OnFileSelected(wnd, fileSelected) {
                                            //NEW: Insert the returned value in the textbox with currentInputID  
                                            var textbox = $get(currentInputID);
                                            textbox.value = fileSelected;
                                        }

                                        var currentInputID = null;
                                            
                                    </script>
                                    <telerik:RadTextBox CssClass="radtextbox" ID="fileName" runat="server" Text='<%# Bind("ThumbImage") %>'
                                        LabelCssClass="" meta:resourcekey="fileNameResource1">
                                    </telerik:RadTextBox>
                                </div>
                            </td>
                            <td colspan="2">
                                <asp:Button Style="margin-top: 0px" ID="selectFile" Text="Open..." runat="server"
                                    OnClientClick='OpenFileExplorerDialog(); return false;' meta:resourcekey="selectFileResource1">
                                </asp:Button>
                                <telerik:RadWindow runat="server" Width="750px" Height="560px" VisibleStatusbar="False"
                                    ShowContentDuringLoad="False" NavigateUrl="Explorer2.aspx" ID="ExplorerWindow"
                                    Modal="True" Behaviors="Close, Move" Behavior="Close, Move" meta:resourcekey="ExplorerWindowResource1">
                                </telerik:RadWindow>
                            </td>
                        </tr>
                        <tr>
                            <td style="padding-bottom: 10; padding-top: 10px">
                                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                    meta:resourcekey="btnUpdateResource1"></asp:Button>
                            </td>
                            <td style="padding-bottom: 10; padding-top: 10px">
                                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                    CommandName="Cancel" meta:resourcekey="btnCancelResource1"></asp:Button>
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
                <PopUpSettings Modal="True"></PopUpSettings>
            </EditFormSettings>
        </MasterTableView>
        <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Office2007">
        </HeaderContextMenu>
    </telerik:RadGrid>
    <asp:EntityDataSource ID="GroupProductEds" runat="server" ConnectionString="name=MLMDataContext"
        DefaultContainerName="MLMDataContext" EnableDelete="True" EnableFlattening="False"
        EnableInsert="True" EnableUpdate="True" EntitySetName="ProductBases" Include="ProductCategory">
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="GroupProductCategoryEds" runat="server" ConnectionString="name=MLMDataContext"
        DefaultContainerName="MLMDataContext" EnableDelete="True" EnableFlattening="False"
        EnableInsert="True" EnableUpdate="True" EntitySetName="ProductCategories">
    </asp:EntityDataSource>
</asp:Content>
